<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Request\CorpRequest;
use App\CustHub\Service\ChCorpService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Mine\MineController;

/**
 * 企业
 */
#[Controller(prefix: 'ch/corp')]
class CorpController extends MineController
{
    #[Inject]
    protected ChCorpService $service;

    #[PostMapping('list')]
    public function list(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->request->all();
        $data['select'] = 'id,corp_name,corp_full_name,remark,auth_corp_id,auth_status';
        return $this->success($this->service->getPageList($data));
    }

    /**
     * 修改备注
     * @param CorpRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('editRemark')]
    public function editRemark(CorpRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除企业
     * @param CorpRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(CorpRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->deleteCorp($request->input('id')) ? $this->success() : $this->error();
    }


    #[PostMapping('selectList')]
    public function selectList(): \Psr\Http\Message\ResponseInterface
    {
        $data = $this->service->getSelectList($this->request->all());
        return $this->success($data);
    }
}